<%@page import="org.passout.projecter.model.Task"%>
<%@page import="org.passout.projecter.common.DbHelper"%>
<%@page import="javax.jdo.Query"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Collection"%>
<%@page import="org.passout.projecter.model.Milestone"%>
<%@ page import="org.passout.projecter.model.Project"%>
<%@ page import="org.passout.projecter.model.PMF"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>

<html>
<head>


<link rel="stylesheet" type="text/css" href="css/date.css" />

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
</head>
  <body>
<%
	if (request.getParameter("pname") == null) {
		response.sendRedirect("/projects.jsp");
	}
	DbHelper dbh = DbHelper.eI();
%>
	<form action="/createmilestone" method="post">
      <div>Name: <input type="text" name="mname"/>
      Due Date: <input type="text" class="datepicker" name="mdate"/>
      <input type="hidden" name="pname" value="<%= request.getParameter("pname")%>"/>
      <input type="submit" value="AddMilestone" /></div>
    </form>


	
	<%
		PersistenceManager pm = PMF.get().getPersistenceManager();
		List<Project> pojects = dbh.findProjectByName(request.getParameter("pname"), pm);
		List<Milestone> miles = pojects.get(0).getMilestones();
	%>
	<h1><%=request.getParameter("pname") +" / "+ pojects.get(0).getName()+":"+pojects.size()%></h1>
	<p>author: <%=pojects.get(0).getAuthor() %></p>
	<p>milestones: <%=pojects.get(0).getMilestones() %></p>
	<div>
	<form action="/createtask" method="post">
      <div>Task Name: <input type="text" name="tname"/>
      Milestone: <select name='mname' id="combo">
      <%for (Milestone m : miles){ %>
      <option value="<%=m.getName() %>"><%=m.getName() %></option>
      <%} %>
     </select>
      <input type="submit" value="AddTask" /></div>
    </form>
	<%
		
		for (Milestone m : miles){
			%>
				<div style="border: 3px coral solid;">
				<h3><%=m.getName() %></h3>
				<% 
				List<Task> tasks = m.getMilestoneTasks();
				if (tasks == null || tasks.size() == 0){
					%>No tasks in milestone
					<%
				} else {
					for (Task t : tasks){
						%>
						<div><%=t.getName() %></div>
						<%
					}
				}
				%>
				</div>			
			<% 
			
		}
	%>
	 </div>
	
	
<script type="text/javascript">
	$(function() {
		$(".datepicker").datepicker({ 
			dateFormat: 'yy-mm-dd', 
			firstDay: 1, 
			monthNames: ['Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември'],
			dayNamesMin: ['Нд','Пн','Вт','Ср','Чт','Пт','Сб']});
	});
	</script>
  </body>
</html>